package cn.wubo.beetsql.controller;

import cn.wubo.beetsql.entity.DemoTableTem;
import cn.wubo.beetsql.service.IDemoTableTemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.Date;
import java.util.List;

@RestController
@RequestMapping("/demoTableTem")
public class DemoTableTemController {

    @Autowired
    IDemoTableTemService demoTableTemService;

    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public List<DemoTableTem> queryUseTemplate() {
        DemoTableTem demoTableTem = new DemoTableTem();
        demoTableTem.setMinDate(new Date(118,2,30));
        demoTableTem.setMaxDate(new Date(118,3,30));
        return demoTableTemService.queryUseTemplate(demoTableTem);
    }

    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public int insertUseTemplate() {
        DemoTableTem demoTableTem = new DemoTableTem();
        demoTableTem.setName("Bane");
        demoTableTem.setTime(new Date(System.currentTimeMillis()));
        return demoTableTemService.insertUseTemplate(demoTableTem);
    }

    @RequestMapping(value = "/update", method = RequestMethod.PUT)
    public int updateUseTemplate() {
        DemoTableTem demoTableTem = new DemoTableTem();
        demoTableTem.setName("Bane");
        DemoTableTem res = demoTableTemService.queryUseTemplate(demoTableTem).get(0);
        res.setName(null);//空值的不会update
        res.setMessage("gl11");
        res.setTime(new Date(System.currentTimeMillis()));
        return demoTableTemService.updateUseTemplate(res);
    }
}
